package com.dreammakerteam.frameworkdemo.base.controller;

import com.dreammakerteam.frameworkdemo.base.domain.RestResult;
import com.dreammakerteam.frameworkdemo.base.service.DAreaService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 地区控制器
 * @author xy
 * @version 0.1
 */
@RestController
@RequestMapping("/system/area")
public class DAreaController extends DBaseController {

    @Resource
    private DAreaService dAreaService;


    /**
     * 获取所有省份
     */
    @RequestMapping("/getProvince")
    public Object getProvince() {
        return dAreaService.getMapper().getProvince();
    }

    /**
     * 获取指定省份下的城市或指定城市下的县区
     * @param parentId 父id
     */
    @RequestMapping("/getByParent")
    public Object getByParent(Long parentId) {
        if (parentId == null || parentId == 0)
            return new RestResult().setSuccess(false).setMsg("请选择上级");
        return dAreaService.getMapper().getByParent(parentId);
    }


}
